﻿
package org.abcFrame.core
{
	
	
	public class AbcController implements IController
	{
		
		private static var _instance : AbcController;  
		private var commands:Dictionary
		
		public static function get instance() : AbcController 
		{
			if ( _instance == null )
				_instance = new AbcController();
			return _instance;
			
		}
		
		public function AbcController() :void
		{
			commands=new Dictionary()
		}
		
		public function registerCommand(type:String) : void{
			
			try{
				var command:AbcCommand = root.loaderInfo.applicationDomain.getDefinition(type) as AbcCommand
				command=new command()
				commands[type] = command
				
				AbcEventDispatcher.instance.addEventListener(type, command.execute)
			}catch (e:ReferenceError) {
				AbcEventDispatcher.instance.dispatcher("getDefinitionByName","getDefinitionByName方法异常:"+e.message)
			}
			
		}
		
		public function removeCommand(type:String) : void{
			
			var command:AbcCommand = commands[type] as AbcCommand
			AbcEventDispatcher.instance.removeEventListener(type,command.execute)
				delete command
		}
		
		
	}
}